<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var minimumNumbers = function (num, k) {
      if (num == 0) return 0
      if (num % 10 == k) return 1
      if (k == 0) return -1
      var num1 = 0
      var count = 0
      while (num1 < num) {
        num1 += k
        ++count
        if ((num1 % 10) == (num % 10)) {
          return count
        }
      }
      return -1
    };
    console.log(minimumNumbers(58, 9));
  </script>
</body>

</html>